package db.swing2;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.HierarchyBoundsAdapter;
import java.awt.event.HierarchyEvent;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.JEditorPane;
import java.awt.Dimension;
import javax.swing.JTextPane;
import java.awt.ComponentOrientation;
import java.awt.Font;

public class GUI extends JFrame {

	private JPanel contentPane;
	JFormattedTextField textFieldSearchTerm;
	final ButtonGroup buttonGroupType = new ButtonGroup();
	JTable tableHitList;
	JTextField textFieldIDN;
	JTree treeUBB;
	JEditorPane editorPaneRecord;
	JScrollPane scrollPaneRecord;
	JButton btnIdnSearchID;
	JButton btnSearchName;
	JScrollPane scrollPaneHilList;
	JScrollPane scrollPaneTreeUBB;
	JLabel labelStatus;
	JTextPane textPaneErrors;
	JLabel lblHitCount;
	JLabel labelRootName;
	JLabel labelRecordName;

	/**
	 * Create the frame.
	 */
	public GUI() {
		setTitle("Hierarchische Darstellung von Schlagwörtern");
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setBounds(100, 100, 1152, 629);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JPanel panelSearch = new JPanel();
		contentPane.add(panelSearch, BorderLayout.NORTH);
		panelSearch.setLayout(new BoxLayout(panelSearch, BoxLayout.Y_AXIS));

		JPanel panelSearchName = new JPanel();
		FlowLayout fl_panelSearchName = (FlowLayout) panelSearchName
				.getLayout();
		fl_panelSearchName.setAlignment(FlowLayout.LEFT);
		panelSearch.add(panelSearchName);

		JLabel lblSuchbegriff = new JLabel("Suchbegriff: ");
		panelSearchName.add(lblSuchbegriff);

		textFieldSearchTerm = new JFormattedTextField();

		panelSearchName.add(textFieldSearchTerm);
		textFieldSearchTerm.setColumns(50);

		btnSearchName = new JButton("trunkiert suchen ...");
		panelSearchName.add(btnSearchName);

		JLabel lblTyp = new JLabel("Typ: ");
		panelSearchName.add(lblTyp);

		JRadioButton rdbtnP = new JRadioButton("p");
		rdbtnP.setEnabled(false);
		panelSearchName.add(rdbtnP);
		buttonGroupType.add(rdbtnP);

		JRadioButton rdbtnB = new JRadioButton("b");
		panelSearchName.add(rdbtnB);
		buttonGroupType.add(rdbtnB);

		JRadioButton rdbtnF = new JRadioButton("f");
		rdbtnF.setEnabled(false);
		panelSearchName.add(rdbtnF);
		buttonGroupType.add(rdbtnF);

		JRadioButton rdbtnU = new JRadioButton("u");
		panelSearchName.add(rdbtnU);
		buttonGroupType.add(rdbtnU);

		JRadioButton rdbtnG = new JRadioButton("g");
		panelSearchName.add(rdbtnG);
		buttonGroupType.add(rdbtnG);

		JRadioButton rdbtnS = new JRadioButton("s");
		panelSearchName.add(rdbtnS);
		rdbtnS.setSelected(true);
		buttonGroupType.add(rdbtnS);

		JRadioButton rdbtnAllTypes = new JRadioButton("beliebig");
		panelSearchName.add(rdbtnAllTypes);
		buttonGroupType.add(rdbtnAllTypes);

		JPanel panelSearchID = new JPanel();
		FlowLayout fl_panelSearchID = (FlowLayout) panelSearchID.getLayout();
		fl_panelSearchID.setAlignment(FlowLayout.LEFT);
		panelSearch.add(panelSearchID);

		JLabel lblIdn = new JLabel("      oder idn: ");
		lblIdn.setHorizontalTextPosition(SwingConstants.LEFT);
		lblIdn.setHorizontalAlignment(SwingConstants.LEFT);
		panelSearchID.add(lblIdn);

		textFieldIDN = new JTextField();
		panelSearchID.add(textFieldIDN);
		textFieldIDN.setColumns(10);

		btnIdnSearchID = new JButton("Idn suchen");
		panelSearchID.add(btnIdnSearchID);

		JSplitPane splitPaneRecord = new JSplitPane();
		contentPane.add(splitPaneRecord, BorderLayout.CENTER);

		JPanel panelRecord = new JPanel();
		splitPaneRecord.setRightComponent(panelRecord);
		panelRecord.setLayout(new BorderLayout(0, 0));

		scrollPaneRecord = new JScrollPane();
		panelRecord.add(scrollPaneRecord, BorderLayout.CENTER);

		editorPaneRecord = new JEditorPane();
		editorPaneRecord.setContentType("text/html");
		editorPaneRecord.setEditable(false);
		scrollPaneRecord.setViewportView(editorPaneRecord);

		JPanel panelRecordInfo = new JPanel();
		scrollPaneRecord.setColumnHeaderView(panelRecordInfo);

		labelRecordName = new JLabel("");
		labelRecordName.setFont(new Font("Tahoma", Font.BOLD, 13));
		panelRecordInfo.add(labelRecordName);

		JSplitPane splitPaneHits = new JSplitPane();
		splitPaneHits.setOrientation(JSplitPane.VERTICAL_SPLIT);
		splitPaneRecord.setLeftComponent(splitPaneHits);

		JPanel panelHitList = new JPanel();
		splitPaneHits.setLeftComponent(panelHitList);
		panelHitList.setLayout(new BoxLayout(panelHitList, BoxLayout.Y_AXIS));

		JPanel panelHitListInfo = new JPanel();
		panelHitList.add(panelHitListInfo);

		JLabel lblTrefferlist = new JLabel("Trefferliste, Zahler der Treffer: ");
		panelHitListInfo.add(lblTrefferlist);

		lblHitCount = new JLabel("");
		panelHitListInfo.add(lblHitCount);

		scrollPaneHilList = new JScrollPane();
		panelHitList.add(scrollPaneHilList);

		tableHitList = new JTable();
		tableHitList.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
			@Override
			public void ancestorResized(HierarchyEvent arg0) {
			}
		});
		tableHitList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

		scrollPaneHilList.setViewportView(tableHitList);

		JPanel panelTree = new JPanel();
		splitPaneHits.setRightComponent(panelTree);
		panelTree.setLayout(new BoxLayout(panelTree, BoxLayout.Y_AXIS));

		JPanel panelTreeInfo = new JPanel();
		panelTree.add(panelTreeInfo);

		JLabel lblBaumdarstellung = new JLabel("Unterbegriffe von: ");
		panelTreeInfo.add(lblBaumdarstellung);
		lblBaumdarstellung.setHorizontalTextPosition(SwingConstants.CENTER);
		lblBaumdarstellung.setHorizontalAlignment(SwingConstants.CENTER);

		labelRootName = new JLabel("");
		panelTreeInfo.add(labelRootName);

		scrollPaneTreeUBB = new JScrollPane();
		panelTree.add(scrollPaneTreeUBB);

		treeUBB = new JTree();
		treeUBB.setModel(null);

		scrollPaneTreeUBB.setViewportView(treeUBB);
		splitPaneHits.setDividerLocation(200);

		JPanel panel = new JPanel();
		panel.setPreferredSize(new Dimension(10, 100));
		contentPane.add(panel, BorderLayout.SOUTH);
		panel.setLayout(new BorderLayout(0, 0));

		labelStatus = new JLabel(" Initialisiere Datenbank ...");
		panel.add(labelStatus, BorderLayout.SOUTH);

		JScrollPane scrollPane = new JScrollPane();
		panel.add(scrollPane);

		textPaneErrors = new JTextPane();
		scrollPane.setViewportView(textPaneErrors);

		JLabel lblFehlermeldungen = new JLabel("Fehlermeldungen:");
		lblFehlermeldungen.setHorizontalAlignment(SwingConstants.CENTER);
		scrollPane.setColumnHeaderView(lblFehlermeldungen);

	}

}
